﻿Imports System.Net
Imports System.Web.Http
Imports Models.Solution

Namespace Controllers

    Public Class ProjectController
        Inherits ApiController

        ''' <summary>
        ''' Get Project By Id
        ''' </summary>
        ''' <param name="id"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <AcceptVerbs("GET")> _
        Public Function [Get](id As Integer) As ProjectVO
            Try
                Dim oService As New Services.Projects(Request)
                Dim oEntity As ProjectVO = oService.Get(id)
                Return oEntity
            Catch ex As Exception
                apiHelpers.ManageException(ex)
            End Try
        End Function


        ''' <summary>
        ''' Get List of Projects
        ''' </summary>
        ''' <param name="solutionId">Optional for filter</param>
        ''' <returns>Array of Projects</returns>
        ''' <remarks></remarks>
        <AcceptVerbs("GET")> _
        Public Function List(solutionId As Integer) As Generic.List(Of ProjectVO)
            Try
                Dim oService As New Services.Projects(Request)
                Return oService.List(solutionId)
            Catch ex As Exception
                apiHelpers.ManageException(ex)
                Return Nothing
            End Try
        End Function

        ''' <summary>
        ''' Update project
        ''' </summary>
        ''' <param name="data">project object</param>
        ''' <returns>Boolean</returns>
        ''' <remarks></remarks>
        <AcceptVerbs("PUT")> _
        Public Function Update(data As ProjectVO) As Integer
            Try
                Dim oService As New Services.Projects(Request)
                Return oService.Update(data)
            Catch ex As Exception
                apiHelpers.ManageException(ex)
                Return -1
            End Try
        End Function

        ''' <summary>
        ''' Create a Project
        ''' </summary>
        ''' <param name="data"></param>
        ''' <returns>The new ID  of the entity</returns>
        ''' <remarks></remarks>
        <AcceptVerbs("POST")> _
        Public Function Create(data As ProjectVO) As Integer
            Try
                Dim oService As New Services.Projects(Request)
                Return oService.Create(data)
            Catch ex As Exception
                apiHelpers.ManageException(ex)
                Return -1
            End Try
        End Function

        ''' <summary>
        ''' Set GeoData on Project
        ''' </summary>
        ''' <param name="data">geoData object</param>
        ''' <returns>GeoData with new Ids created</returns>
        ''' <remarks></remarks>
        <AcceptVerbs("PUT")> _
        Public Function SetGeoData(data As MapDataVO) As MapDataVO
            Try
                Dim oService As New Services.Projects(Request)
                Return oService.SetGeoData(data)
            Catch ex As Exception
                apiHelpers.ManageException(ex)
                Return Nothing
            End Try
        End Function

        ''' <summary>
        ''' Return GeoData info from Project
        ''' </summary>
        ''' <param name="id">projectId</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <AcceptVerbs("GET")> _
        Public Function GetGeoData(id As Integer) As MapDataVO
            Try
                Dim oService As New Services.Projects(Request)
                Return oService.GetGeoData(id)
            Catch ex As Exception
                apiHelpers.ManageException(ex)
            End Try
        End Function

        ''' <summary>
        ''' Return geodata from Project
        ''' </summary>
        ''' <param name="projectId"></param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        <AcceptVerbs("GET")> _
        Public Function GetGeoAttributes(projectId As Integer) As Dictionary(Of String, Generic.List(Of Generic.KeyValuePair(Of String, String)))
            Try
                Dim oService As New Services.Projects(Request)
                Return oService.GetGeoAttributes(projectId)
            Catch ex As Exception
                apiHelpers.ManageException(ex)
            End Try
        End Function

        ''' <summary>
        ''' Delete a project
        ''' </summary>
        ''' <param name="id">projectId</param>
        ''' <returns>1 if OK</returns>
        ''' <remarks></remarks>
        <AcceptVerbs("DELETE")>
        Public Function Delete(id As Integer) As Integer
            Try
                Dim oService As New Services.Projects(Request)
                Return oService.Delete(id)
            Catch ex As Exception
                apiHelpers.ManageException(ex)
                Return -1
            End Try
        End Function

    End Class

End Namespace